{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Populating the interactive namespace from numpy and matplotlib\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: pylab import has clobbered these variables: ['require', 'clf', 'invert', 'add', 'mod', 'inv', 'repeat']\n",
      "`%matplotlib` prevents importing * from pylab and numpy\n"
     ]
    }
   ],
   "source": [
    "%pylab inline\n",
    "from operator import *\n",
    "import numpy as np\n",
    "# 区分测试集和训练集\n",
    "from sklearn.cross_validation import train_test_split\n",
    "# svm\n",
    "from sklearn import svm\n",
    "# knn\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "# 交叉验证\n",
    "from sklearn.cross_validation import cross_val_score\n",
    "# 画图\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# payload\n",
    "f_pl = open('src/payload.txt')\n",
    "# keyword\n",
    "f_key = open('src/key_list.txt')\n",
    "# normal requrire\n",
    "f_norm = open('src/normal_require.txt')\n",
    "# f_norm = open('src/replace1.txt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 先把读进来的东西变成数组\n",
    "pl_list = []\n",
    "for line in f_pl.readlines():\n",
    "    # 去掉最后的换行符\n",
    "    line=line.strip('\\n')\n",
    "    pl_list.append(line)\n",
    "key_list = []\n",
    "for line in f_key.readlines():\n",
    "    line=line.strip('\\n')\n",
    "    key_list.append(line)\n",
    "norm_list = []\n",
    "for line in f_norm.readlines():\n",
    "    line=line.strip('\\n')\n",
    "    norm_list.append(line)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def changePayload(payload):\n",
    "    p_list = []\n",
    "    # 无关单词转化,key保留\n",
    "#     for word.lower() in payload:\n",
    "#         # 在key list中的敏感词\n",
    "#         if word in key_list:\n",
    "#             p_list.append(word)\n",
    "#         # 非敏感词\n",
    "#         elif (\"normal_word\" not in p_list):\n",
    "#             p_list.append(\"normal_word\")\n",
    "#         else:\n",
    "#             continue\n",
    "\n",
    "\n",
    "\n",
    "    for word in key_list:\n",
    "        if word in payload.lower():\n",
    "            p_list.append(word)\n",
    "        elif(\"normal_word\" in payload):\n",
    "            p_list.append(\"normal_word\")\n",
    "        else:\n",
    "            continue\n",
    "            \n",
    "            \n",
    "\n",
    "    # 特殊字符转化\n",
    "    for i in payload:\n",
    "        ascii = ord(i)\n",
    "        if(ascii<48 or ascii>57 and ascii<65 or ascii>90 and ascii < 95 or ascii>95 and ascii<97 or ascii>122):\n",
    "            if(('ascii'+ str(ascii)) not in p_list):\n",
    "               p_list.append('ascii'+str(ascii))\n",
    "            if(i != \" \"):\n",
    "                payload = payload.replace(i,\" \")\n",
    "    # 16进制转化\n",
    "    payload = payload.split(\" \")\n",
    "    for word in payload:\n",
    "        if(word[0:2] == \"0x\"):\n",
    "            p_list.append(\"16hex\")\n",
    "            payload.remove(word)\n",
    "    \n",
    "    return p_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 创建文本训练集向量\n",
    "def createDocVec(payloads,requires):\n",
    "    vec = set([])\n",
    "    for doc in payloads:\n",
    "        vec = vec | set(doc)\n",
    "    for doc in requires:\n",
    "        vec = vec | set(doc)\n",
    "    return list(vec)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 函数：为每一个训练样本生成一个向量，词集模型\n",
    "def wordToVec(vecList,doc):\n",
    "    returnVec = [0] * len(vecList)\n",
    "    for word in doc:\n",
    "        # 如果\n",
    "        if(word in vecList):\n",
    "            returnVec[vecList.index(word)] = 1\n",
    "        else:\n",
    "            print(\"word is not contained:  \" + word)\n",
    "    return returnVec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# payload 和正常请求的数组转化\n",
    "payloads = []\n",
    "for pl in pl_list:\n",
    "    payloads.append(changePayload(pl))\n",
    "requires = []\n",
    "for req in norm_list:\n",
    "    requires.append(changePayload(req))\n",
    "# payload和正常请求的向量转化\n",
    "vec_list = createDocVec(payloads,requires)\n",
    "payloads_vec = []\n",
    "requires_vec = []\n",
    "for payload in payloads:\n",
    "    payloads_vec.append(wordToVec(vec_list,payload))\n",
    "for require in requires:\n",
    "    requires_vec.append(wordToVec(vec_list,require))\n",
    "# payload 向量和普通请求向量\n",
    "payloads_vec = np.array(payloads_vec)\n",
    "requires_vec = np.array(requires_vec)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 生成X\n",
    "X = np.concatenate((payloads_vec,requires_vec))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 生成Y\n",
    "Y = []\n",
    "for i in range(0,len(payloads_vec)):\n",
    "    Y.append(1)\n",
    "for i in range(0,len(requires_vec)):\n",
    "    Y.append(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAEPCAYAAAC3NDh4AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmcXvPd//HXO4mIxBoiiCaWWGpPEEFbo1Fiq6KtUNWq\nrTciXbSWtrdx311of10suVshtlqipYqWEpVpG0uFLEQTCZFICKp2giyf3x/nDJfJdc2cyZxrzjUz\n7+fjMY+5zrm+55zPeMj1ub67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Sfprev+JSjaT2plkobTD0lVUVy8T9ybA3cA5\nEfHnMve9DVgTeFTSF0qeM73xOWm5qyT9WtJD6TPL3ErfAg4ADo2I90ve+xnw/bL/VWEG8LqkERXe\nty7OScI6hHTjnodJFnmDpBbxu/T1uyTfnHcDPk2yXHPZ2zQ9kSadS4AjI2J34Crgx2WuvQS4KiJ2\nJqm9XBIRM4D/JlnCZGhEvFfmumvSsrdW+LsOA95Jr/99yXN2aXxOSfEBETE8Is4sc6u9gVOAA0v2\nBWn8mx8E3pO0T7kQgB8BPygXn5mThHUkE0iSA+nvxsXeBPxE0gzgXmATSRtmvOc2wA4k+z5MI2l6\n2aRMuT1Lnvdbkg/lLCYCx0rq1UyZ0gUqm3tOc0tkP5XeZ/8K966YCNLNu6Jpn4oZOElYx3IbMELS\nEGCNiJiWnv8SsAEwJN0P4yWg6YfyMj76/3vj+wJmpt/kh0TEzhFxICtb1b6NnwJTgJvTxRPLiQqv\nm3q7mfdeINm34leS6lZ6QMQkkr95eIXrf0zSJOXF3OwjnCSsw4iIt4EGkqXXS5eMXgd4KSJWSNqX\nZNOXRo3fpBcA26UjftYlWcYZ4EmSjt3hkDQ/Vdhs6QE+7Dg/FvhHK+L+JvB6Gnc5pTWJtjznKZJt\nKK+TVG7P9x8B361w7URgPaAm94q34jhJWEdzI8kHWWmSuB7YPW1uOpaPruEfABGxiKQPYyZJs9XU\n9PxS4PPAhZKmkyzvvGeZ554BHJ+W+RIwJkOspd/KvwpsVGGYa2m5Ss/J9A0/3UDoeOB2SZuXXhcR\nd5HUsird60c0s42ldU1eKtzMzCpyTcLMzCpykjAzs4qcJMzMrCInCTMzq8hJwszMKnKSMDOzipwk\nzMysIicJMzOr6P8DkO3FRZNLPgcAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10372f650>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.89863945697869096, 0.91575798552481769, 0.91535496275250827, 0.973238422878825, 0.77768668503239158, 0.77768668503239158, 0.58040571826501997, 0.58060722965117473, 0.58100923847833119]\n"
     ]
    }
   ],
   "source": [
    "# knn here\n",
    "# X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.3)\n",
    "# # knn\n",
    "knn = KNeighborsClassifier()\n",
    "# # 训练\n",
    "# knn.fit(X_train,Y_train)\n",
    "\n",
    "k_range = range(1, 10)\n",
    "k_scores = []\n",
    "for k in k_range:\n",
    "    knn = KNeighborsClassifier(n_neighbors=k)\n",
    "##    loss = -cross_val_score(knn, X, y, cv=10, scoring='mean_squared_error') # for regression\n",
    "    scores = cross_val_score(knn, X,Y, cv=10, scoring='accuracy') # for classification\n",
    "    k_scores.append(scores.mean())\n",
    "# print k_scores\n",
    "\n",
    "plt.plot(k_range, k_scores)\n",
    "plt.xlabel('Value of K for KNN')\n",
    "plt.ylabel('Cross-Validated Accuracy')\n",
    "plt.show()\n",
    "print k_scores\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.8326791   0.99950932  1.          1.          1.          1.          1.\n",
      "  1.          1.          1.        ]\n",
      "0.983218842002\n"
     ]
    }
   ],
   "source": [
    "# svm 交叉验证\n",
    "\n",
    "# 设置算法\n",
    "clf = svm.SVC(gamma=0.001)\n",
    "\n",
    "# 用测试集预测 \n",
    "scores = cross_val_score(clf, X,Y, cv=10, scoring='accuracy')\n",
    "print scores\n",
    "print scores.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,\n",
       "  decision_function_shape=None, degree=3, gamma=0.001, kernel='rbf',\n",
       "  max_iter=-1, probability=False, random_state=None, shrinking=True,\n",
       "  tol=0.001, verbose=False)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据分割 \n",
    "X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.2)\n",
    "# 设置算法\n",
    "clf = svm.SVC(gamma=0.001)\n",
    "# 训练\n",
    "clf.fit(X,Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "payload 分类错误\n",
      "'=0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'<1#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1'<99#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'=0=1#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'=0=1=1=1=1=1#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'!=2!=3!=4#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'|0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'&0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'^0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'<<0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'>>0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'&''#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'%11&1#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'&1&1#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'|0&1#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'<<0|0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'*9#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'/9#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'%9#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'+0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'-0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'+2+5-7#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'+0+0-0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'-0-0-0-0-0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'*9*8*7*6*5#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'/2/3/4#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'%12%34%56%78#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'/**/+/**/0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'+++0+++++0*0#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "admin' order by'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "admin' group by'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'='\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'<>'1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'>1='\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'>1='\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "0'='0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "0'='0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'=round(0,1)='1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'=round(0,1)='1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'*0*'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'*0*'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'+'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'+'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'-'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'-'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'+1-1-'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "'+1-1-'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1 and 1=0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1 and 1=1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1=0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1=1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1<>0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1<>1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1<0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1<1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1*0*0*1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1*0*0*0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1%1%1%0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1%1%1%1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1 div 0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1 div 1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1 regexp 0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1 regexp 1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1^0\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=1^1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?num=0^(id regexp 0x61646d696e)\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT /*COMMENT*/ 1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT user()\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT system_user()\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT user FROM mysql.user\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT host, user, password FROM mysql.user\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT schema_name FROM information_schema.schemata; (MySQL >= 5.0)\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT distinct(db) FROM mysql.db (need priv)\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SLEEP(5)-- \n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "id=1 OR SLEEP(25)=0 LIMIT 1-- \n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "id=1) OR SLEEP(25)=0 LIMIT 1-- \n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "id=1)) OR SLEEP(25)=0 LIMIT 1-- \n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?id=4\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?id=5-1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?id=4 OR 1=1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?id=-1 OR 17-7=10\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "DROP sampletable;--\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "DROP sampletable;#\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "DROP/**/sampletable;\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "DR/**/OP/**/sampletable;\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT IF(1=1, 1, 2)\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT CONCAT(CHAR(75),CHAR(76),CHAR(77))\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT * FROM mysql.user WHERE 1 LIMIT 1,1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT * FROM mysql.user\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT user, password FROM mysql.user\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT user, password FROM mysql.user LIMIT 1,1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT schema_name FROM information_schema.schemata;\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "SELECT schema_name FROM information_schema.schemata LIMIT 1,1;\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "tblUsers -> tablename\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "find table which have a column called 'username'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "?vulnerableParam=-99 OR IF((ASCII(MID(({INJECTON}),1,1)) = 100),SLEEP(14),1) = 0 LIMIT 1--\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "id=1/*!uNIon*/SeLeCt+1,2,3--\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1 || substr(user,1,1) = lower(conv(11,10,36))\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1 || substr(user,1,1) = unhex(61)\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1 || substr(user,1,1) = lower(conv(10,10,36\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "3922\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "4282\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1)))\"(',)\"'\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "6189-6188\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1.6JWSt\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1'LiodiB<'\">ajmWWU\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1) AND 5859=6981 AND (2820=2820\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1) AND 5631=5631 AND (3728=3728\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1 AND 6335=6348\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1 AND 5631=5631\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1 AND 8922=2803-- edTe\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1 AND 5631=5631-- kTQJ\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "-4123\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1' ORDER BY 1-- WbTI\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1' ORDER BY 3414-- axcH\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1' ORDER BY 10-- svph\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1' ORDER BY 6-- Nuhs\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1' ORDER BY 4-- eqrk\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1' ORDER BY 3-- joOB\n",
      "\n",
      "\n",
      "payload 分类错误\n",
      "1\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 查看分类错了的样本\n",
    "for i in range(len(X)):\n",
    "    temp = np.array(X[i]).reshape((1,-1))\n",
    "    if(clf.predict(temp)[0] != Y[i]):\n",
    "        # 如果预测错误，打印出原文\n",
    "        if i < len(pl_list):\n",
    "            print \"payload 分类错误\"\n",
    "            print pl_list[i]\n",
    "        else:\n",
    "            print \"正常请求分类错误\"\n",
    "            print norm_list[(i-len(pl_list))]\n",
    "        print \"\\n\"\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 0, 1]])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " np.array([1,0,1]).reshape((1, -1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#扩充数据\n",
    "#数据清洗\n",
    "#分析分类失败的样本\n",
    "#考虑贝叶斯分析融合进算法的可能性\n",
    "#增加手工payload，用于测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"sli\" in \"sli skadi asdkfi\"\n",
    "#     print word"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 're' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-27-d9d80c3f8986>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0ma\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mre\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mr'a'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 're' is not defined"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
